<template>
	<view class="wish-list">
		<view class='list-con' v-for='item, index in dataList' :key='index'>
			<image mode="widthFix" :src="item.configurePic"></image>
			<view class='c-title'>
				<view class='t-header'>{{item.modelName}}</view>
				<view class='t-sub'>
					<!-- {{item.servciepkgInfos.join(' | ')}} -->
					<!-- <view class='sub-list' v-for='(item, index) in item.uniqueserverInfos' :key='item'>{{item}}{{index == subList.length - 1 ? '': ' | '}}</view> -->
					<view class='sub-list'>{{item.modelConfigureName}} | </view>
					<view class='sub-list'>{{item.colorName}}</view>
				</view>
				<view class='t-price'>￥{{item.orderAmount}}</view>
				<view class='t-footer'>
					<view class='f-date'>{{item.createTime}}</view>
					<view class='f-btn' @click='toDetail(item.id)'>查看详情</view>
					<view class='f-delete' @click='deleteItem(item.id)'>
						<image mode="widthFix" src="https://pfmotortest.hb4oss.xstore.ctyun.cn/appstatic/img/order-delete.png"></image>
					</view>
				</view>
			</view>
		</view>
		<view v-if="params.pageEnd && dataList.length" class="end">全部加载完毕</view>
		<empty v-if='!dataList.length' text='暂无心愿单数据' />
	</view>
</template>

<script>
	const app = getApp();
	import empty from '@components/empty/empty.vue'
	const network = require('@manager/network-manager.js');
	const dialog = require('@utils/dialog.js');
	export default {
		components: {
			empty
		},
		data() {
			return {
				dataList: [],
				params: {
					pageNum: 1,
					pageSize: 5,
					pageEnd: false
				}
			}
		},
		onLoad: function(options) {
			
		},
		onShow: function() {
			this.getList(1)
		},
		onReachBottom() {
			this.getList(this.params.pageNum)
		},
		methods: {
			getList(pageNum) {
				if (pageNum == 1) {this.dataList = []; this.params.pageNum = 1; this.params.pageEnd = false}
				let url = app.globalData.config.interfaces.URL_CAR_ORDER_CONFIGURE_PAGE
				let params = {
					"loginId":app.globalData.userInfo.id,
					pageNum: pageNum,
					pageSize: this.params.pageSize
				}
				if (this.params.pageEnd) return
				network.get(url, params, 'form').then(res => {
					uni.stopPullDownRefresh()
					if (res.code == 200) {
						this.dataList = this.dataList.concat(res.data.list)
						if (!res.data.list.length) {this.params.pageEnd = true;return}
						this.params.pageNum++
					}
				})
			},
			toDetail(id) {
				uni.navigateTo({
					url: `/module_my/pages/wishDetail/wishDetail?id=${id}`
				});
			},
			deleteItem(id) {
				let _this = this
				uni.showModal({
					title: '删除心愿单',
					content: '您确认要删除心愿单吗?',
					confirmColor: '#EA5404',
					success: function (res) {
						if (res.confirm) {
							let url = app.globalData.config.interfaces.URL_CAR_ORDER_CONFIGURE_DELETE
							network.post(url, {id: id}, 'form').then(res => {
								if (res.code == 200) {
									uni.showToast({
										title:'删除成功!',
										duration: 3000,
										icon: 'none'
									})
									_this.getList(1)
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		},
	}
</script>

<style>
	@import "./wishList.css";
</style>
